<template>
  <div class="charge-container">
    <van-nav-bar 
      title="充值" 
      left-text="返回" 
      left-arrow 
      @click-left="onClickLeft"  
      right-text="我的充值订单" 
      @click-right="onClickRight"
      class="modern-nav"
    />
    
    <div class="charge-content">
      <div class="content-header">
        <h2 class="section-title">账户充值</h2>
        <p class="section-desc">请输入您要充值的金额</p>
      </div>
      
      <div class="input-group">
        <span class="label">充值金额：</span>
        <el-input 
          v-model="total" 
          placeholder="请输入充值金额" 
          clearable
          class="amount-input"
        >
          <template #prefix>
            <span class="currency-symbol">¥</span>
          </template>
        </el-input>
      </div>
      
      <el-button type="primary" class="submit-btn" @click="addOrder()">
        <span class="btn-text">确认充值</span>
      </el-button>
    </div>
  </div>
</template>
<script setup>


//返回按钮事件
import {ref} from "vue";
import router from '@/router';
import {addRechargeOrder} from "@/api/pay";
import {ElMessage} from "element-plus";

const onClickLeft = () => history.back();
const onClickRight = () => {
  router.push('/my/rechargeOrder')
}
const total = ref(0)

function addOrder(){
  addRechargeOrder(total.value).then(res =>{
    console.log(res.data)
    if (res.data.code===200000){
      ElMessage.success(res.data.errorMessage)
      total.value=0
    }else {
      ElMessage.error(res.data.errorMessage)
      total.value=0
    }
  })
}


</script>
<style scoped>
.charge-container {
  min-height: 100vh;
  background-color: #f8fafc;
  padding-bottom: 32px;
}

.charge-content {
  padding: 32px 24px;
  margin: 20px 16px;
  background-color: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.charge-content:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

.content-header {
  margin-bottom: 32px;
  text-align: center;
}

.section-title {
  font-size: 24px;
  color: #1a1a1a;
  margin: 0 0 8px;
  font-weight: 600;
}

.section-desc {
  font-size: 14px;
  color: #666;
  margin: 0;
}

.input-group {
  display: flex;
  align-items: center;
  margin-bottom: 32px;
}

.label {
  font-size: 16px;
  color: #333;
  margin-right: 16px;
  white-space: nowrap;
  font-weight: 500;
}

.amount-input {
  flex: 1;
  max-width: 320px;
}

.currency-symbol {
  color: #666;
  font-weight: 500;
  margin-right: 4px;
}

.submit-btn {
  width: 100%;
  height: 48px;
  font-size: 16px;
  border-radius: 8px;
  transition: all 0.3s ease;
  border: none;
  background: linear-gradient(135deg, #409eff, #3a8ee6);
}

.submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
}

.btn-text {
  font-weight: 500;
  letter-spacing: 1px;
}

:deep(.van-nav-bar) {
  background-color: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

:deep(.van-nav-bar__title) {
  font-size: 18px;
  font-weight: 600;
  color: #1a1a1a;
}

:deep(.van-nav-bar__text) {
  color: #409eff;
}

:deep(.el-input__inner) {
  height: 48px;
  line-height: 48px;
  font-size: 16px;
  border-radius: 8px;
  border-color: #e4e7ed;
  transition: all 0.3s ease;
}

:deep(.el-input__inner):focus {
  border-color: #409eff;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.1);
}

:deep(.el-input__inner):hover {
  border-color: #409eff;
}

:deep(.el-input__prefix) {
  left: 12px;
}

@media (max-width: 768px) {
  .charge-content {
    margin: 16px 12px;
    padding: 24px 16px;
  }
  
  .section-title {
    font-size: 20px;
  }
  
  .amount-input {
    max-width: 100%;
  }
}
</style>